package org.apache.servicecomb.samples.practise.houserush.realestate.dao;

import org.apache.servicecomb.samples.practise.houserush.realestate.entity.House;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface HouseDao extends JpaRepository<House, Integer> {
    //批量查询
    @Query("select h from House h where h.id in (?1)")
    //@Query("SELECT h FROM House h WHERE h.id in (?1)")
    List<House> findAllByIdInForUpdate(List<Integer> ids);

    //根据id批量修改房源
    @Modifying
    @Query("update House h set h.state = 'locking' where h.id in (?1)")
    int updateLockingStatesForHouse(List<Integer> ids);

    @Modifying
    @Query("update House h set h.state = 'new' where h.id in (?1)")
    int updateReleaseLockingStatesForHouses(List<Integer> ids);

}
